#pragma once

#include<string>
#include <chrono>
#include <format_interface.hh>
#include <cJSON.h>

class memory_load : public format_interface{
    public:
        explicit memory_load(std::string mem_info = "/proc/meminfo",
                std::string mem_info_process = "/proc/self/status",
                std::string mem_info_process_prefix = "/proc/"):total_memory_in_KB(0),
                current_memory_usage_in_KB(0),
                memory_info_file(std::move(mem_info)),
                memory_info_process_file(std::move(mem_info_process)),
                memory_info_process_prefix_file(std::move(mem_info_process_prefix))
                {
                    current_memory_avail_in_KB = 0;
                };
        uint64_t get_total_memory_in_KB();
        uint64_t get_current_memory_usage_in_KB();
        float    get_current_memory_usage_in_percent();

        uint64_t get_memory_used_by_process(int pid);

        virtual cJSON* to_json();
        virtual const char*  get_name();
        ~memory_load();

    private:
        uint64_t total_memory_in_KB;
        uint64_t current_memory_usage_in_KB;
        uint64_t  current_memory_avail_in_KB;
        std::string memory_info_file;
        std::string memory_info_process_file;
        std::string memory_info_process_prefix_file;
        std::chrono::time_point<std::chrono::steady_clock> time_stamp;

    private:
        bool parse_memory_file();

};


